package com.sun.service.pms.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.pojo.PmsProduct;
import com.sun.mapper.pms.PmsProductMapper;
import com.sun.service.pms.IPmsProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品信息 服务实现类
 * </p>
 *
 * @author 妙妙屋
 * @since 2021-12-15
 */
@Service
public class PmsProductServiceImpl extends ServiceImpl<PmsProductMapper, PmsProduct> implements IPmsProductService {

    @Autowired
    private PmsProductMapper pmsProductMapper;
    @Override
    public IPage selectAll(Long pageSize, Long pageNum, String keyword, PmsProduct pmsProduct) {
//        return pmsProductMapper.selectList(null);

        Page<PmsProduct> page = new Page<>(pageNum,pageSize);
        QueryWrapper<PmsProduct> qr = new QueryWrapper<>();
        //关键词搜索
        if(StringUtils.isNotBlank(keyword)){
            qr.like("name",keyword);
        }
        if(StringUtils.isNotBlank(pmsProduct.getProductSn())){
            qr.eq("product_sn",pmsProduct.getProductSn());
        }


        if(pmsProduct.getProductCategoryId()!=null){
            qr.eq("product_category_id",pmsProduct.getProductCategoryId());
        }


        if(pmsProduct.getBrandId()!=null){
            qr.eq("brand_id",pmsProduct.getBrandId());
        }

        if(pmsProduct.getPublishStatus()!=null){
            qr.eq("publish_status",pmsProduct.getPublishStatus());
        }

        if(pmsProduct.getVerifyStatus()!=null){
            qr.eq("verify_status",pmsProduct.getVerifyStatus());
        }

        Page<PmsProduct> p = pmsProductMapper.selectPage(page, qr);
        return p;
    }
}
